/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ASAInst;

import ASAExpr.ASAExpr;
import exception.DivisionByZeroException;
import exception.VariableNonDeclareeException;

/**
 *
 * @author FM & KB
 */
public class ASAInstPrint extends ASAInst {
    
    private String chaine = null;
    private ASAExpr expression = null;
    
    public ASAInstPrint(String chaine){
       //On retire les guillemets, à voir si meilleure solution
       this.chaine = chaine.substring(1, chaine.length()-1);
    }
    
    public ASAInstPrint(ASAExpr expression){
        this.expression = expression;
    }

    @Override
    public void executer()throws VariableNonDeclareeException, DivisionByZeroException {
        if(this.chaine != null){
            System.out.println(chaine);
        }
        else if(expression != null){
            System.out.println(expression.evalue());
        }
    }

    @Override
    public String notationExplorateur(String prefixe) {
        String res = prefixe + getLabelExplorateur() + "\n";
        String prefixeSuiv = prefixe + "   ";

        if (chaine != null) {
            res += "    " + chaine + "\n";
        } else {
           res += expression.notationExplorateur(prefixeSuiv);
        }
        return res;
    }

    @Override
    public String getLabelExplorateur() {
        return "PRINT";
    }
}
